package com.project.lk.nurseapp.msg;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;

import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.project.lk.nurseapp.R;
import com.project.lk.nurseapp.base.BaseActivity;
import com.project.lk.nurseapp.base.UrlContants;
import com.project.lk.nurseapp.msg.presenter.AppMsgPresenter;
import com.project.lk.nurseapp.msg.presenter.IAppMsgView;
import com.project.lk.nurseapp.utils.AppManager;
import com.project.lk.nurseapp.utils.LocationList;
import com.project.lk.nurseapp.utils.XViewSettingUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
/**
 * 功能介绍：
 * 项目名：
 * 模块名称：
 * 作者：LK
 * 日期：2018/1/9
 * 修改日期：
 */
public class AppMsgActivity extends BaseActivity  implements IAppMsgView{


    @BindView(R.id.xrecyclerview)
    XRecyclerView xrecyclerview;
    private AppMsgAdapter adapter;
    private AppMsgPresenter presenter;

    @Override
    protected void initData() {
        presenter = new AppMsgPresenter(this);
        presenter.refresh(UrlContants.NOTIFY_LIST_URL);
        adapter = new AppMsgAdapter(presenter.getList(),this);
        LinearLayoutManager manager = new LinearLayoutManager(this);
        XViewSettingUtils.setting(xrecyclerview, adapter,manager);
        xrecyclerview.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
                presenter.refresh(UrlContants.NOTIFY_LIST_URL);
            }

            @Override
            public void onLoadMore() {
                presenter.loadMore(UrlContants.NOTIFY_LIST_URL);
            }
        });

    }

    @Override
    protected void initView() {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_app_msg;
    }


    @OnClick(R.id.back)
    public void onViewClicked() {
        AppManager.getAppManager().finishActivity();
    }

    @Override
    public void showList() {
        if (adapter!=null) {
            adapter.notifyDataSetChanged();
            xrecyclerview.refreshComplete();
            xrecyclerview.loadMoreComplete();
        }
    }

    @Override
    public void fail() {
        if (xrecyclerview!=null) {
            xrecyclerview.loadMoreComplete();
            xrecyclerview.refreshComplete();
        }
    }

    @Override
    public void noMore() {
        if (xrecyclerview!=null) {
            xrecyclerview.loadMoreComplete();
            xrecyclerview.refreshComplete();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (presenter!=null) {
            presenter.dettachView();
            presenter=null;
        }
    }
}
